package com.mxpio.erp.common.inventory.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.mxpio.erp.common.jpa.policy.ResCodeGeneratorPolicy;
import com.mxpioframework.jpa.annotation.Generator;
import com.mxpioframework.security.annotation.Dict;
import com.mxpioframework.security.entity.BaseEntity;
import com.mxpioframework.security.entity.User;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.util.Date;

@Data
@EqualsAndHashCode(callSuper=false)
@Entity
@Table(name = "MB_ERP_INV_INVENTORY_PLAN")
@Schema(description="盘点计划")
public class InventoryPlan extends BaseEntity {

private static final long serialVersionUID=1L;

    @Id
    @Generator(policy = ResCodeGeneratorPolicy.class)
    @Column(name = "CODE_")
    @Schema(description = "计划编码")
    private String code;

    @Column(name = "NAME_")
    @Schema(description = "计划名称")
    private String name;

    @Column(name = "EXEC_STATUS_")
    @Schema(description = "执行状态")
    @Dict(dicCode = "ERP_INV_PLAN_EXEC_STATUS")//待执行1，执行中2，已完成3，已作废4
    private String execStatus;

    @Column(name = "PLAN_TYPE_")
    @Schema(description = "计划类型")
    @Dict(dicCode = "ERP_INV_PLAN_TYPE")
    private String planType;//静态、循环、动态

    @Column(name = "START_DATE_")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
    @Schema(description = "计划开始日期")//计划开始执行的日期
    private Date startDate;

    /*@Column(name = "TASK_PLAN_START_TIME_")
    @JsonFormat(timezone = "GMT+8",pattern = "HH:mm:ss")
    @Schema(description = "任务开始时间")//生成的任务，开始执行时间
    private String taskPlanStartTime;

    @Column(name = "TASK_PLAN_END_TIME_")
    @Schema(description = "任务结束时间")//生成的任务，开始执行时间
    private Date taskPlanEndTime;*/

    @Column(name = "RATE_")
    @Schema(description = "频率")
    private String rate;

    @Column(name = "RATE_UNIT_")
    @Schema(description = "频率单位")
    @Dict(dicCode = "ERP_INV_PLAN_RATE_UNIT")
    private String rateUnit;

    @Column(name = "IS_ENABLE_")
    @Schema(description = "是否启用")
    @Dict(dicCode = "ERP_COMMON_YESNO")
    private Integer isEnable;

    /*@Column(name = "IS_AUTO_")
    @Schema(description = "是否自动下达")
    @Dict(dicCode = "ERP_COMMON_YESNO")
    private Integer isAuto;

    @Column(name = "ADVANCE_TIME_")
    @Schema(description = "提前下达时间(天)")//按天
    private Integer advanceTime;*/


    @Column(name = "END_LOOP_TYPE_")
    @Schema(description = "结束类型")
    @Dict(dicCode = "ERP_INV_PLAN_END_LOOP_TYPE")
    private String endLoopType;//循环、频次、定时

    @Column(name = "END_TIMES_")
    @Schema(description = "结束次数")//结束类型为频次时
    private Integer endTimes;

    @Column(name = "END_DATE_")
    @Schema(description = "结束日期")//结束类型为定时
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd")
    private Date endDate;

    @Column(name = "IS_EXCLUDE_ZERO_")
    @Schema(description = "库存为0不参与盘点")
    @Dict(dicCode = "ERP_COMMON_YESNO")
    private Integer isExcludeZero;

    @Column(name = "IS_APPEND_")
    @Schema(description = "盘点中允许增加物料")
    @Dict(dicCode = "ERP_COMMON_YESNO")
    private Integer isAppend;

    @Column(name = "IS_EXCLUDE_SCRAP_")
    @Schema(description = "物料状态为报废不参与盘点")
    @Dict(dicCode = "ERP_COMMON_YESNO")
    private Integer isExcludeScrap;

    @Column(name = "CRITERIA_",length = 5000)
    @Schema(description = "盘点范围")
    private String criteria;

    @Column(name = "LAST_PLAN_START_")
    @Schema(description = "上次计划开始时间")//循环执行时 计算使用
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    private Date lastPlanStart;

    @Column(name = "LAST_PLAN_END_")
    @Schema(description = "上次计划结束时间")
    @JsonFormat(timezone = "GMT+8",pattern = "yyyy-MM-dd HH:mm:ss")
    private Date lastPlanEnd;

    @Column(name = "MEMO_")
    @Schema(description = "备注")
    private String memo;

    @Column(name = "INVENTORY_WAY_")
    @Schema(description = "盘点方法")
    @Dict(dicCode="ERP_INV_INVENTORY_WAY") //1 盲盘，0明盘
    private String inventoryWay;

    @Column(name = "WH_CODE_")
    @Schema(description = "盘点仓库")
    @Dict(dicCode = "whCode" ,dicEntity = Warehouse.class, dicText = "whName")
    private String whCode;

    @Column(name = "BUSI_DATE_")
    @Schema(description = "账务日期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date busiDate;

    @Column(name = "INVENTORY_PLAN_DATE_")
    @Schema(description = "计划盘点日期")
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    private Date inventoryPlanDate;

    @Column(name = "INVENTORY_RANGE_")
    @Schema(description = "盘点范围")
    @Dict(dicCode="ERP_INV_INVENTORY_RANGE")
    private String inventoryRange;

    @Column(name = "INVENTORY_PERCENTAGE_")
    @Schema(description = "盘点比例(%)")
    private Integer inventoryPercentage;

    @Column(name = "INVENTORY_RANGE_BASIS_")
    @Schema(description = "比例依据")
    @Dict(dicCode="ERP_INV_INVENTORY_RANGE_BASIS")
    private String inventoryRangeBasis;

    @Column(name = "INVENTORY_PERSONS_")
    @Schema(description = "盘点人员")
    @Dict(dicCode = "username", dicEntity = User.class, dicText = "nickname")
    private String inventoryPersons;

    @Column(name = "INVENTORY_TYPE_")
    @Schema(description = "单据类型")
    @Dict(dicCode="ERP_INV_INVENTORY_TYPE")//初盘、复盘
    private String inventoryType;

    @Column(name = "CYCLE_PERCENTAGE_")
    @Schema(description = "每次循环比例(%)")
    private Integer cyclePercentage;

    @Column(name = "CYCLED_ITEM_CODES_",length = 999)
    @Schema(description = "已经循环过的物料编码，以逗号分隔")
    private String cycledItemCodes;
}
